public class Answer2 {
    //最长无重复子数组
    //https://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4?tpId=196&tqId=37149&ru=/exam/oj
    public int maxLength (int[] arr) {
        int[] hash=new int[100000];
        int n=arr.length;
        int ret=0;
        for(int left=0,right=0;right<n;right++){
            hash[arr[right]] ++;
            while(hash[arr[right]] > 1){
                hash[arr[left++]] --;
            }
            ret=Math.max(ret,right-left+1);
        }

        return ret;
    }
}
